<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *公告管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';

if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['groupid']){
		$params['groupid']=intval($_RQ['groupid']);
		$return['params']['groupid']=$_RQ['groupid'];
	}
	$return['list']=pdo_getall('jy_yxw_worker',$params,$fields);
	$params2=array('status'=>1,'uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['y']) && !empty($_RQ['m'])){
		$m=intval($_RQ['m']);
		$yuestart = mktime(0,0,0,$m,1,$_RQ['y']);
		if($m<12){
			$yueend = mktime(0,0,0,$m+1,1,$_RQ['y']);
		}else{
			$y=$_RQ['y']+1;
			$yueend = mktime(0,0,0,1,$_RQ['y']);
		}
		$yueend -=100;
		$params2['pay_time between']=array($yuestart,$yueend);
	}elseif(!empty($_RQ['y'])){
		$yuestart = mktime(0,0,0,1,1,$_RQ['y']);
		$yueend = mktime(0,0,0,1,1,$_RQ['y']+1);
		$yueend -=100;
		$params2['pay_time between']=array($yuestart,$yueend);
	}
	if(!empty($_RQ['y'])){
		$return['params']['y']=$_RQ['y'];
	}
	if(!empty($_RQ['m'])){
		$return['params']['m']=$_RQ['m'];
	}
	
	foreach($return['list'] as $k=>&$v){
		$params2['workerid']=$v['id'];
		$v['total']=pdo_count('jy_yxgz_orderlog',$params2);
		$v['totalprice']=pdo_getsum('jy_yxgz_orderlog',$params2,'price');
		$v['benprice']=pdo_getsum('jy_yxgz_orderlog',$params2,'benprice');
		$v['lifee']=price($v['totalprice']-$v['benprice'],'int');
	}
	paixu($return['list'],'totalprice','desc');
	foreach($return['list'] as $k=>&$v){
		$v['rank']=$k+1;
	}
	$htmls=array(
		'type'=>'list',
		'list'=>array('data'=>'list','delall'=>false,'del_one'=>false,'edit'=>false,'list'=>array(
			array('name'=>'rank','title'=>'排行','type'=>'string'),
			array('name'=>'title','title'=>'员工姓名','type'=>'string'),
			array('name'=>'gangwei','title'=>'岗位名称','type'=>'string'),
			array('name'=>'juese','title'=>'角色','type'=>'radio','options'=>'juese'),		
			array('name'=>'total','title'=>'销售量','type'=>'string'),
			array('name'=>'totalprice','title'=>'销售额','type'=>'string'),
			array('name'=>'lifee','title'=>'利润','type'=>'string'),
		)),
		'search'=>array(
			array('name'=>'y','width'=>10,'title'=>'年份','type'=>'radio','options'=>'ys'),
			array('name'=>'m','width'=>10,'title'=>'月份','type'=>'radio','options'=>'months'),
			array('name'=>'groupid','width'=>10,'title'=>'部门','type'=>'select','options'=>'groups'),
		)
	);
	$return['juese']=$this->user_juese;
	$return['htmls']=$htmls;
	$nowy=date('Y');
	$y1=$nowy-2;
	$y2=$nowy-1;
	$return['ys']=array(
		$y1=>$y1.'年',
		$y2=>$y2.'年',
		$nowy=>$nowy.'年',
	);
	$return['months']=array(
		'01'=>'1月',
		'02'=>'2月',
		'03'=>'3月',
		'04'=>'4月',
		'05'=>'5月',
		'06'=>'6月',
		'07'=>'7月',
		'08'=>'8月',
		'09'=>'9月',
		'10'=>'10月',
		'11'=>'11月',
		'12'=>'12月',
	);
	exi($return);
}
